package com.chenchao.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/25 19:52
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.net.Test08B.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 客户端
 */
public class Test08B {
    public static final String CLOSE="886";
    public static void main(String[] args) throws IOException {
        /*选码头,不填参数，系统给一个随机码头*/
        DatagramSocket socket = new DatagramSocket();
        /*建集装箱*/
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String s = br.readLine();
            if (CLOSE.equals(s)){
                break;
            }
            byte[] bytes = new byte[]{127,0,0,1};
            /*使用字节数组创建地址*/

            DatagramPacket dp = new DatagramPacket
                    (s.getBytes(),0,s.getBytes().length,
                            InetAddress.getByAddress(bytes),10000);
            /*开船*/
            socket.send(dp);
        }
        /*关码头*/
        socket.close();
    }
}
